// JavaScript source code
(function () {
    var O = "http://fetch.im.baidu.com/ihaloader",
    P = "",
    T = null,
    J = null,
    R = null,
    L = null,
    Q = null,
    C = false,
    I = false;
    var K = function (W, V) {
        T = N.F(V);
        P = W || "";
        if (T == null) {
            return
        }
        H();
        G();
        S();
        F()
    };
    var H = function () {
        if (/msie (\d+\.\d)/i.test(navigator.userAgent)) {
            C = (document.documentMode || parseFloat(RegExp["\x241"])) == 6
        }
    };
    var G = function () {
        var V = N.C("link", {
            href: "http://st0.im.baidu.com/bubble/iknow/bdimBubble.css",
            type: "text/css",
            rel: "stylesheet"
        });
        N.A(V, document.getElementsByTagName("head")[0]);
        J = N.C("span", {
            className: "bdim_bubble_containter"
        });
        R = N.C("div", {
            className: "bdim_bubble_logo",
            title: "\u53d1\u8d77\u5373\u65f6\u4f1a\u8bdd"
        });
        L = N.C("div", {
            className: "bdim_bubble_pop",
            title: "\u53d1\u8d77\u5373\u65f6\u4f1a\u8bdd"
        });
        Q = N.C("div", {
            className: "bdim_bubble_popText"
        });
        T.innerHTML = "";
        N.A(J, T);
        N.A(R, J);
        N.A(L, J);
        N.A(Q, L);
        A()
    };
    var S = function () {
        IMOld = (function () {
            var Z = null;
            var Y = 0;
            var a = null;
            var W = null;
            b.interval = 30 * 1000;
            b.url = O + "?op=msgcount&charset=gbk&callback=IMOld&refer=hi.baidu.com";
            b.url += "&un=" + P;
            b.reset = function () {
                b.onchange(0);
                d(0);
                if (b.timer) {
                    clearInterval(b.timer)
                }
                X()
            };
            b.fetch = function () {
                Z = V();
                W = new Date().getTime();
                if (Z) {
                    Z = Z.split("|");
                    W = parseInt(Z[1], 36);
                    Y = Z[0];
                    Z = null
                }
                window.setTimeout(function () {
                    e();
                    X();
                    if (Y > 0 && typeof (b.onchange) == "function") {
                        b.onchange(Y)
                    }
                },
                1000)
            };
            b.stopFetch = function () {
                if (b.timer) {
                    window.clearInterval(b.timer)
                }
            };
            function e() {
                d(Y);
                a = document.createElement("SCRIPT");
                a.charset = "gb2312";
                a.type = "text/javascript";
                a.src = b.url + (b.url.indexOf("?") > 0 ? "&" : "?") + ".stamp=" + new Date().getTime().toString(36);
                document.getElementsByTagName("HEAD")[0].appendChild(a)
            }
            function d(h) {
                var f = new Date();
                var g = f.getTime();
                f.setTime(g + 3 * b.interval);
                document.cookie = "IM_old=" + h + "|" + g.toString(36) + ";domain=baidu.com;path=/;expires=" + f.toGMTString();
                if (a) {
                    a.parentNode.removeChild(a);
                    a = null
                }
            }
            function V() {
                var c = document.cookie.match(/(^| )IM_old=([^;]*)(;|$)/);
                if (c != null) {
                    return unescape(c[2]);
                    return null
                }
            }
            function X() {
                b.timer = setInterval(function () {
                    var f = V();
                    var h = 0;
                    var g = 0;
                    if (f) {
                        f = f.split("|");
                        g = parseInt(f[1], 36);
                        h = f[0];
                        f = null
                    }
                    if (Math.abs(new Date().getTime() - g) > b.interval) {
                        e()
                    }
                    if (Y != h) {
                        Y = h;
                        if (typeof (b.onchange) == "function") {
                            b.onchange(h)
                        }
                    }
                },
                1000)
            }
            function b(c) {
                d(c)
            }
            return b
        })();
        IMOld.onchange = function (V) {
            V == "0" ? A() : M(V)
        }
    };
    var F = function () {
        R.onclick = U;
        L.onclick = U;
        D()
    };
    var D = function () {
        IMOld.fetch()
    };
    var M = function (X) {
        var V = J.clientWidth;
        if (C) {
            J.style.width = "16px";
            J.style.marginRight = V - 16 + "px"
        }
        L.style.display = "";
        Q.innerHTML = X;
        I = true;
        var W = L.clientWidth;
        if (C) {
            J.style.marginRight = "0px";
            J.style.width = V + "px"
        }
        B(J, 16 - 9 + W,
        function () {
            E(L)
        })
    };
    var A = function () {
        if (!I) {
            L.style.display = "none";
            return false
        }
        L.style.display = "none";
        B(J, 16);
        I = false
    };
    var U = function () {
        A();
        try {
            startBaiduHi("active", P, "", {})
        } catch (V) { }
    };
    var N = {
        F: function (V) {
            if ("string" == typeof V || V instanceof String) {
                return document.getElementById(V)
            } else {
                if (V && V.nodeName && (V.nodeType == 1 || V.nodeType == 9)) {
                    return V
                }
            }
            return null
        },
        C: function (W, X) {
            var Y = document.createElement(W);
            for (var V in X) {
                Y[V] = X[V]
            }
            return Y
        },
        A: function (V, W) {
            return W ? W.appendChild(V) : document.body.appendChild(V)
        }
    };
    var E = function (c, Z, V) {
        var Y = [0, 25, 50, 75, 100],
        X = [],
        a = 0,
        b = 5;
        if (Z) {
            Y = Y.reverse()
        }
        var W = window.setInterval(function () {
            var d = Y.shift();
            c.style.filter = "Alpha(opacity=" + d + ")";
            c.style.opacity = d / 100;
            X.push(d);
            if (Y.length == 0) {
                Y = X.reverse();
                X = [];
                a++
            }
            if (a == b) {
                window.clearInterval(W);
                V && V()
            }
        },
        30)
    };
    var B = function (b, a, V) {
        var Y = b.clientWidth,
        X = 3,
        Z = a > Y;
        if (Y == a) {
            V && V();
            return
        }
        var W = window.setInterval(function () {
            var c = b.clientWidth;
            if (c == a) {
                window.clearInterval(W);
                V && V();
                return
            }
            var d = Math.ceil(Math.abs(c - a) / X);
            d = d < 1 ? 1 : d;
            b.style.width = Z ? c + d + "px" : c - d + "px"
        },
        20)
    };
    if (window.bdimBubble) {
        window.bdimBubble.init = K
    } else {
        window.bdimBubble = {
            init: K
        }
    }
})();